package com.example.easycharge.service;

import com.alibaba.fastjson.JSONObject;
import com.example.easycharge.entity.ChargePile;
import com.example.easycharge.entity.Report;
import com.example.easycharge.repository.ChargePileRepository;
import com.example.easycharge.repository.ReportRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;

@Service
public class ReportService {
    @Autowired
    private ChargePileRepository chargePileRepository;
    @Autowired
    private ReportRepository reportRepository;

    public List<Report> getRealTimeReports() {
        List<ChargePile> allPile = chargePileRepository.findAll();
        List<Report> reportList = new ArrayList<>(allPile.size());
        for (ChargePile chargePile : allPile) {
            reportList.add(new Report(chargePile));
        }
        return reportList;
    }

    public JSONObject initReport() {
        reportRepository.initReport();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("report", "已完成报告的初始化");
        return jsonObject;
    }
}
